package com.fengpanlong.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.fengpanlong.entity.File;
import com.fengpanlong.entity.Filetype;
import com.fengpanlong.util.DBHelp;
import com.fengpanlong.util.RowMapper;

public class FiletypeDao {
	private DBHelp<Filetype> db = new DBHelp<Filetype>();
	
	public List<Filetype> findAll(String employeeid) {
		String sql = "select id,name,filename,filesize,createtime,filetypeid,employeeid from t_flie where employeeid=?";
		return db.executeQueryForList(sql, new FiletypeRowMapper(), employeeid);
	}
	
	public int findbyid(String filetypeid) {
		String sql ="select count(*) as total  from t_flie where filetypeid=?";
		return db.executeQueryForCount(sql, filetypeid);
	}
	public void save(Filetype filetype) {
		String sql = "insert into t_filetype (id,namecratetime,projectid,employeeid) values(?,?,?,?)";
		db.executeSQL(sql,filetype.getId(),filetype.getCreatetime(),filetype.getProjectId(),filetype.getEmployeeId());
	}
	

	
	private class FiletypeRowMapper implements RowMapper<Filetype> {

		public Filetype mapperRow(ResultSet rs) throws SQLException {
			Filetype f = new Filetype();
			f.setId(rs.getString("id"));
			f.setName(rs.getString("name"));
			f.setCreatetime(rs.getString("createtime"));
			f.setEmployeeId(rs.getString("employeeId"));
			f.setProjectId(rs.getString("projectId"));
			return f;
		}
		
	}
}
